package com.lqk.singleton.enumsingleton;

/**
 * @author lqk
 * @date 2021/11/30 15:40
 */
public class EnumSingleton {
    public static void main(String[] args) {
        Singleton instance = Singleton.INSTANCE;
        Singleton instance2 = Singleton.INSTANCE;
        System.out.println(instance == instance2);

        instance.sayOk();
    }
}

// 使用枚举实现单例模式
enum Singleton{
    INSTANCE;   // 属性
    public void sayOk(){
        System.out.println("ok");
    }
}
